package cn.tedu.boot.ers.controller;

import cn.tedu.boot.ers.pojo.dto.OrderAddDTO;
import cn.tedu.boot.ers.pojo.vo.OrderDetailsVO;
import cn.tedu.boot.ers.service.IOrderService;
import cn.tedu.boot.ers.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/orders")
@Api(tags = "订单模块")
public class OrderController {
    @Autowired
    IOrderService service;

    @PostMapping("/insert")
    @ApiOperation("新增订单")
    public JsonResult<Void> insert(OrderAddDTO orderAddDTO) {
        service.insert(orderAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("用户查询自己的订单")
    @GetMapping("get/order/details")
    public JsonResult<List<OrderDetailsVO>> getOrderDetailsByUserId(Long userId) {
        List<OrderDetailsVO> orderDetails = service.getOrderDetails(userId);
        return JsonResult.ok(orderDetails);
    }

    @ApiOperation("管理员查询餐馆所有订单")
    @GetMapping("get/all/order/details")
    public JsonResult<List<OrderDetailsVO>> getAllOrderDetails() {
        List<OrderDetailsVO> orderDetails = service.getAllOrderDetails();
        return JsonResult.ok(orderDetails);
    }
}
